package com.tql.pandian.controller;


import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.system.api.domain.SysUser;
import com.tql.pandian.entity.ResultDTO;
import com.tql.pandian.entity.analysis.dto.PanDianCodeDTO;
import com.tql.pandian.entity.dto.EndInventoryDTO;
import com.tql.pandian.entity.dto.ProductPositiveDTO;
import com.tql.pandian.entity.vo.EndInventoryVo;
import com.tql.pandian.service.ICommonService;
import com.tql.pandian.service.IPanDianAnalysisService;
import com.tql.pandian.util.CommonUtilHll;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.Date;
import java.util.List;

@ApiOperation("分析展示")
@RestController
@RequestMapping("/panDianAnalysis")
public class PanDianAnalysisController extends BaseController {
    @Autowired
    private ICommonService commonService;
    @Autowired
    private IPanDianAnalysisService panDianAnalysisService;

    @ApiOperation("期末库存-获取下拉时间区间")
    @Log(title = "期末库存-获取下拉时间区间", businessType = BusinessType.OTHER)
    @GetMapping("/getDropDown/{byMonth}")
    public AjaxResult getDropDown(@PathVariable("") String byMonth){
        //获取店信息

        return success(panDianAnalysisService.getByMoth(byMonth));
    }


    @ApiOperation("分析展示-期末库存")
    @Log(title = "分析展示-期末库存")
    @GetMapping("/getEndInventory")
    public TableDataInfo getEndInventory(EndInventoryDTO dto){
        startPage();
        List<EndInventoryVo> list = panDianAnalysisService.getEndInventory(dto);
        return getDataTable(list);
    }

    @ApiOperation("分析展示-产品优势分析-销量top10")
    @Log(title = "分析展示-产品优势分析-销量top")
    @GetMapping("/getProductPositive")
    public AjaxResult getProductPositive(ProductPositiveDTO dto) throws ParseException {
        if (StringUtils.isEmpty(dto.getParamTime())) {
            dto.setParamTime(CommonUtilHll.getLastDay(new Date()));
        }

        String deptCode = SecurityUtils.getLoginUser().getSysUser().getDeptCode();
        String shopId1 = commonService.getEnabledHllShopIdByKingdeeFnumber(deptCode);
        dto.setShopId(shopId1);
        if (SecurityUtils.isAdmin(SecurityUtils.getUserId()))
            return null;
        return success(panDianAnalysisService.getProductPositive(dto));
    }

    @ApiOperation("分析展示-产品优势分析-毛利总金额top10菜品")
    @Log(title = "分析展示-产品优势分析-毛利总金额top10菜品")
    @GetMapping("/getProductPositiveProfit")
    public AjaxResult getProductPositiveProfit(ProductPositiveDTO dto) throws ParseException {
        if (StringUtils.isEmpty(dto.getParamTime())) {
            dto.setParamTime(CommonUtilHll.getLastDay(new Date()));
        }

        String deptCode = SecurityUtils.getLoginUser().getSysUser().getDeptCode();
        String shopId1 = commonService.getEnabledHllShopIdByKingdeeFnumber(deptCode);
        dto.setShopId(shopId1);
        if (SecurityUtils.isAdmin(SecurityUtils.getUserId()))
            return null;
        return success(panDianAnalysisService.getProductPositiveProfit(dto));
    }

    @ApiOperation("获取盘点Code")
    @Log(title = "获取盘点Code", businessType = BusinessType.OTHER)
    @GetMapping("/getPanDianCode")
    public AjaxResult getPanDianCode(PanDianCodeDTO dto){
        return success(panDianAnalysisService.getPanDianCode(dto));
    }

}
